<template>
	<view class="">
		
		<sc-tour :assemble="assemble" v-if="datashow" @detailTap="detailTap"></sc-tour>
		<uni-load-more :loadingType="loadingType" :contentText="contentText" v-if="datashow"></uni-load-more>
		<sc-no v-if="!datashow" :noStatus="true" @navtive="navtive" url="add_images/no_data.png" nofont="暂无拼团商品" width="25%" ></sc-no>
		<sc-home></sc-home>
		<shop-loading v-if="shopLoad"></shop-loading>
	</view>
</template>

<script>
	import scTour from '../../pages/components/sc-tour.vue';
	import {assemble} from '@/common/group.js';
	import uniLoadMore from '@/components/uni-load-more.vue';
	import list from '@/mixins/list.js'
	import scNo from '@/components/sc-no/sc-no.vue';
	export default {
		components: {
			scTour,
			uniLoadMore,
			scNo
		},
		data () {
			return {
				datashow:false,
				assemble:[],
				shopLoad: true,
			}
		},
		mixins: [list],
		methods: {
			navtive(){
				uni.reLaunch({
					url:'/pages/index/index'
				})
			},
			toproductdetail (index) {
				uni.navigateTo({
					url: '/pageB/classify/productdetail?id='+index + '&type=' + '3'
				})
			},
			getDuration(my_time) {
			  var days    = my_time / 1000 / 60 / 60 / 24;
			  var daysRound = Math.floor(days);
			  var hours = parseInt((my_time % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
			  var minutes = parseInt((my_time % (1000 * 60 * 60)) / (1000 * 60));
			  var seconds = parseInt(my_time % (1000 * 60)) / 1000;
			  // console.log('转换时间:', daysRound + '天', hoursRound + '时', minutesRound + '分', seconds + '秒');
			  
			  let dateInfo = {
				  day:daysRound,
				  h:hours,
				  m:minutes,
				  s:seconds
			  };
			  return dateInfo;
			},
			getData() {
				this.shopLoad = true;
				assemble({page:this.page}).then(res => {
					console.log(res)
					if(res.code == 1){
						let data = res.msg.data
						if (data.length) {
							data.forEach((item,index)=>{
								let da = (item.time*1000) - (item.now_time*1000);
								item.dateInfo = this.getDuration(da)
							})
							this.assemble = data
							this.datashow = true;
							this.page = res.msg.current_page
							this.last_page = res.msg.last_page
							uni.hideLoading();
							uni.stopPullDownRefresh();
							this.loadingType = res.msg.last_page > 1 ? 0 : 2;
						}
						this.shopLoad = false;
					}else{
						this.shopLoad = false;
						uni.hideLoading();
						uni.stopPullDownRefresh();
						
					}
					
				}).catch()
			},
			getmoreNews() {
				if (this.loadingType !== 0) { //loadingType!=0;直接返回
					return false;
				}
				this.loadingType = 1;
				uni.showLoading({
					title: '加载中'
				});
				if (this.page == this.last_page) {
					uni.hideLoading();
					uni.stopPullDownRefresh(); //得到数据后停止下拉刷新
				} else {
					this.page++;
					var that = this
					assemble({page:this.page}).then(res => {
						if(res.code == 1){
							var itemProduct = res.msg.data
							that.assemble = that.assemble.concat(itemProduct)
							this.loadingType = this.page == this.last_page ? 2 : 0
						}
					}).catch()
					uni.hideLoading();
			
				}
			},
			//商品跳转
			detailTap(item){
				uni.navigateTo({
					url:'/pageB/classify/productdetail?type=3&id='+item.id
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	
	.pro_list {
		width: 100%;
		background-color: #FFFFFF;
		padding: 0 30upx;
		padding-top: 30upx;
		box-sizing: border-box;
		overflow: hidden;
		.list {
			width: 100%;
			display: flex;
			align-items: center;
			&:last-child{
				.list_info{
					border: none;
				}
			}
		}
		image {
			width: 218upx;
			height: 218upx;
			margin-right: 40upx;
			border-radius: 10upx;
		}
		.list_info {
			padding-top: 16upx;
			flex: 1;
			height: 240upx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			border-bottom: 2upx solid #e1e1e1;
			padding-bottom: 25upx;
			.list_info_title {
				font-size: 30upx;
				color: #333333;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
			}
			.list_info_title_2{
				margin-top: 15upx;
				font-size: 26upx;
				color: #999;
			}
			.list_info_groupnum {
				width: 100upx;
				height: 30upx;
				background-image: url(../../static/image/index/ic-tour.png);
				background-repeat: no-repeat;
				background-size: cover;
				font-size: 18upx;
				line-height: 30upx;
				color: #FFFFFF;
				text-align: center;
			}
			.list_info_residueday {
				font-size: 24upx;
				color: #333333;
				line-height: 52upx;
			}
			.list_info_bottom{
				display: flex;
				justify-content: space-between;
				align-items: flex-end;
			}
			.list_info_price {
				font-size: 30upx;
				color: #f73e2f;
				text {
					margin-left: 10upx;
					font-size: 26upx;
					color: #999999;
					text-decoration: line-through;
				}
			}
			.togroup {
				
				width: 145upx;
				height: 52upx;
				border-radius: 26upx;
				background: linear-gradient(to right,#FD7377 0%,#FF2842 100%);
				font-size: 26upx;
				color: #FFFFFF;
				text-align: center;
				line-height: 52upx;
			}
		}
	}
</style>
